sysroot: Update some code to use fstatat_allow_noent API
authorColin Walters <walters@verbum.org>
Wed, 17 Oct 2018 16:06:50 +0000 (16:06 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 17 Oct 2018 16:17:18 +0000 (16:17 +0000)
It's much easier to read and use correctly.  Making this change
since I saw an unprefixed error in an issue.

Closes: #1757
Approved by: jlebon

src/libostree/ostree-sysroot.c

index 4b2c654ca695758ed952970fa2963730231e1a81..8a916289f1f783530b09dc87a59ea60945cec9c5 100644 (file)
@@ -376,12 +376,11 @@ _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
 
   g_autofree char *ostree_bootdir_name = g_strdup_printf ("ostree/boot.%d", bootversion);
   struct stat stbuf;
-  if (fstatat (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW) != 0)
+  if (!glnx_fstatat_allow_noent (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
+    return FALSE;
+  if (errno == ENOENT)
     {
-      if (errno == ENOENT)
-        *out_subbootversion = 0;
-      else
-        return glnx_throw_errno (error);
+      *out_subbootversion = 0;
     }
   else
     {
@@ -499,10 +498,10 @@ read_current_bootversion (OstreeSysroot *self,
   int ret_bootversion;
   struct stat stbuf;
 
-  if (fstatat (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW) != 0)
+  if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW, error))
+    return FALSE;
+  if (errno == ENOENT)
     {
-      if (errno != ENOENT)
-        return glnx_throw_errno (error);
       ret_bootversion = 0;
     }
   else
@@ -976,11 +975,12 @@ ostree_sysroot_load_if_changed (OstreeSysroot  *self,
       /* Otherwise - check for /sysroot which should only exist in a deployment,
        * not in ${sysroot} (a metavariable for the real physical root).
        */
-      else if (fstatat (self->sysroot_fd, "sysroot", &stbuf, 0) < 0)
+      else
         {
-          if (errno != ENOENT)
-            return glnx_throw_errno_prefix (error, "fstatat");
-          self->is_physical = TRUE;
+          if (!glnx_fstatat_allow_noent (self->sysroot_fd, "sysroot", &stbuf, 0, error))
+            return FALSE;
+          if (errno == ENOENT)
+            self->is_physical = TRUE;
         }
       /* Otherwise, the default is FALSE */
     }